<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8">
    <title>sowRecord</title>
    <script type="text/javascript" src="../../plugs/jquery-3.1.1.min.js"></script>
    <script src="../../assets/bootstrap/js/bootstrap.min.js"></script>
    <!-- boostrap table  -->
   	
	<!-- bootstrap -->
	<link rel="stylesheet" href="../../plugs/bootstrap/css/bootstrap.min.css">
	<script type="text/javascript" src="../../plugs/bootstrap/js/bootstrap.min.js"></script>
	<!-- 分页插件 -->
	<link rel="stylesheet" href="../../plugs/bootstrap-table/bootstrap-table.min.css">
	<script type="text/javascript" src="../../plugs/bootstrap-table/bootstrap-table.min.js"></script>
	<script type="text/javascript" src="../../plugs/bootstrap-table/bootstrap-table-locale-all.min.js"></script>
	<!-- 行内编辑 -->
	<script type="text/javascript" src="../../plugs/editable/bootstrap-editable.js"></script>
	<script type="text/javascript" src="../../plugs/editable/bootstrap-table-editable.js"></script>
	<link rel="stylesheet" href="../../css/layer/mobile/need/layer.css">
	<script type="text/javascript" src="../../css/layer/layer.js"></script>
    <link rel="stylesheet" href="../../business/Form/css/Form.css">
</head>
<body>
<!--查询列表-->
<div class="container" style="margin-top:20px;width: 1200px">
			<!-- 表格 -->
				 <div id="toolbar">
        			<button value="删除" id="delete">删除</button>
				</div>


			<div class="row">
				<div class="col-xs-12">
					<table class="table table-striped table-bordered table-hover" ></table>
				</div>
			</div>
</div>


<!--  -->
<script src="../js/buttonStyleCover.js"></script>
<script>
$(document).ready(function() 
		{
						var businessId = $(window.parent.parent.frames["topFrame"].document).find('#businessId').text();
				    	 //---先销毁表格 ---
				        $('table').bootstrapTable('destroy');  
				        //---初始化表格,动态从服务器加载数据--- 
				       // alert("hello");
						 $('table').bootstrapTable
						 ({
							//发送数据请求
					    	url: '../getPageWorkers.do',
							method: 'post',
							contentType: "application/x-www-form-urlencoded",
							toolbar: '#toolbar',//自定义工具栏
							cache: false,
							height: 600,
							striped: true,
							//search: true,
							//showExport: true,
							//showColumns: true,
							exportTypes: ['csv','txt','xml'],
							clickToSelect: true,
							//【查询设置】
							/* queryParamsType的默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
				                             设置为 ''  在这种情况下传给服务器的参数为：pageSize,pageNumber */
							queryParamsType:'', 
				           	queryParams: function queryParams(params) {
				             var param = {  
				                 pageNumber: params.pageNumber,    
				                 pageSize: params.pageSize,
				                 businessId: businessId
				             }; 
				             /*
				             for(var key in searchArgs){
				           	  param[key]=searchArgs[key]
				             }  
				             */
				             return param;                   
				           }, 
							//【其它设置】
				           locale:'zh-CN',//中文支持
				           pagination: true,//是否开启分页（*）
				           pageNumber:1,//初始化加载第一页，默认第一页
				           pageSize: 10,//每页的记录行数（*）
				           pageList: [10,15,20],//可供选择的每页的行数（*）
				           sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
				           showRefresh:true,//刷新按钮
				           //【设置列属性】
							columns:
							 [
							 {field: 'check',checkbox: true},
							 {field: 'workerId',title: '员工id'}, 	
							 {field: 'businessId',title: '企业编码'},	 
							 {field: 'workerNum',title: '员工账号'},
							 {field: 'workerPhone',title: '电话'},
							 {field: 'roleName',title: '角色'},
							 {field: 'workerName',title: '员工姓名'}
							
							 /*
							 {field: 'seedsource',title: '地点', align: 'center',
								formatter:function(value,row,index){
								    var element = 
								    "<a class='edit' data-id='"+row.id +"'>编辑</a> "+ 
								    "<a class='delet' data-id='"+row.id +"'>删除</a> ";
								    return element;  
								} 
							  }
							  */
							],
				           
							//行内编辑保存事件
							onEditableSave: function (field, row, oldValue, $el)
							{
								update(row);
							}	
				           
				           
				       });	 
					  //删除数据
					  $('#delete').click(function(){
						 var rows = $('table').bootstrapTable('getSelections');
						 var rowsNum = rows.length;
						 if(rowsNum == 0)
						 {
							 layer.msg("未选择数据",{icon: 5})
						 }
						 else
						 {
							 //alert(rows[0].check);
							 //删除第一个check对象，后台不需要，必须处理
							 for(var i =0 ;i< rowsNum ;i++)
								delete rows[i]['check'];
							 $.ajax({
								  type: "post",
								  url: "../delWorker.do",
								  data:{data:JSON.stringify(rows)},
								  //data:	rows,
								  success: function (data, status) {
									  if (status == "success") {
										  layer.msg("删除成功",{icon: 1})
					                        //成功之后页面数据删除
					                        $('table').bootstrapTable('refresh');
					                    }
					                },
					                error: function () {
										layer.msg("删除失败",{icon: 5})
					                }
					            });
						  }
					  });
					  
						
					  //修改数据  
					  function update(row)
					  {
						  //向服务器提交数据
						  $.ajax({
							  type: "post",
							  url: "../updateRole.do",
							  //data:{data:JSON.stringify(rows)},
							  data:	row,
							  success: function (data, status) {
								  if (status == "success") {
									  layer.msg("修改成功",{icon: 5})
				                    }
				                },
				                error: function () {
									layer.msg("修改失败",{icon: 5})
				                }
				            });      
						  //end
					  } 
				  	});	
	
	
	
</script>
</body>
</html>